#include "Vector2.h"

SGF::Vector2::Vector2()
{
	_x = 0;
	_y = 0;
}

SGF::Vector2::Vector2( Real64 x, Real64 y )
{
	_x = x;
	_y = y;
}

SGF::Vector2::Vector2( const Vector2& src )
{
	_x = src._x;
	_y = src._y;
}

SGF::Vector2& SGF::Vector2::operator=( const Vector2& src )
{
	_x = src._x;
	_y = src._y;
	return* this;
}

SGF::Real64 SGF::Vector2::operator*( const Vector2& src )
{
	return _x * src._x + _y * src._y;
}

SGF::Vector2& SGF::Vector2::operator+=( const Vector2& src )
{
	_x += src._x;
	_y += src._y;
	return* this;
}

SGF::Vector2& SGF::Vector2::operator-=( const Vector2& src )
{
	_x -= src._x;
	_y -= src._y;
	return* this;
}

SGF::Vector2 SGF::Vector2::operator+( const Vector2& src )
{
	return Vector2(_x + src._x, _y + src._y);
}

SGF::Vector2 SGF::Vector2::operator-( const Vector2& src )
{
	return Vector2(_x - src._x, _y - src._y);
}

SGF::Real64 SGF::Vector2::Length( const Vector2& src )
{
	return Math<Real64>::Sqrt(src._x * src._x + src._y * src._y);
}

SGF::Vector2 SGF::Vector2::Normalize( const Vector2& src )
{
	Real64 len = Math<Real64>::Sqrt(src._x * src._x + src._y * src._y);
	return Vector2(src._x / len, src._y / len);
}

SGF::Real64& SGF::Vector2::operator[]( int index )
{
	switch (index)
	{
	case 0:
		return _x;
	case 1:
		return _y;
	default:
		throw 10;
	}
}

std::ostream& SGF::operator<<( std::ostream& stream, Vector2& src )
{
	stream << "(" << src._x << "," << src._y << ")";
	return stream;
}